<?php

namespace app\admin\model;

use app\admin\traits\ScopeUniacid;
use app\common\model\TimeModel;

class KnscyOrders extends TimeModel
{

    protected $name = "orders";
    protected $globalScope = ['uniacid'];
    use ScopeUniacid;

    protected $deleteTime = "delete_time";
    //订单的 order_status 的各种值记录
    //0: 刚创建
    //1: 订单表，订单产品表，订单日志表数据保存完整，可以发起支付
    // 支付的状态用 pay_status = 1,2 记录 1= 进入过支付，2=支付参数设置正常能发起支付 ,3= 支付异步通知notify 成功
    //2: 支付成功 notify通知成功
    public function getIsNotPaidAttr( $value, $data ){
        //订单是否支付
        if($data['status_label'] == 'unpaid' && $data['order_status']==1){
            return 1;
        }
        return 0;
    }
    public function getTotalPriceAttr( $value, $data ){
        return number_format( max(0,$data['order_money'] - $data['discount_money']));
    }
    public function getOrderMoneyAttr( $value ){
        return number_format($value);
    }
    /**
     * @param $key
     * @return string|string[]
     */
    public static function statusLabels( $key = null )
    {
        $arr =  [
            'unpaid'=>'待支付',
            'process' => '待出行',
            'completed' =>'已完成',//待评价
            'refund' => '已退款',
            'cancel' => '已取消', //订单无效未支付用户自己取消/系统取消/到期取消

        ];
        return $key === null ? $arr : (isset($arr[$key]) ? $arr[$key] : '全部');
    }

    /**
     * 把status_label 对应到 状态对应进度的初始值
     * @param $key
     * @return int
     */
    public static function label2Status( $key = null )
    {
        $arr =  [
            'unpaid'=>'1',
            'process' => '21',
            'completed' =>'31',//待评价
            'refund' => '41',
            'cancel' => '0', //订单无效未支付用户自己取消/系统取消/到期取消

        ];
        return $arr[$key] ?? '0';
    }
    
    public function getPayStatusList()
    {
        return ['0'=>'未支付','1'=>'待支付', '2'=>'支付中','3'=>'已支付'];
    }

    public function getCanRefundList()
    {
        return ['0'=>'否','1'=>'是',];
    }

    public function getNeedCheckList()
    {
        return ['0'=>'否','1'=>'是',];
    }

    public function getStatusList()
    {
        return ['0'=>'禁用','1'=>'启用',];
    }


}